Computer programmers write source code for software using one of various types of programming languages. The source code is typically enclosed in one or more statements that contain the logic that is later executed by a computer. The term “statement” is used broadly herein as covering function, method, or procedure invocations, statement blocks, and/or other portions of logic that are executed by a computer. In sequential programming, source code can be written to execute statements that follow a certain sequential order. For example, statement A may be executed, followed by the execution of statement B.
Software transactional memory is a concurrency control mechanism analogous to database transactions for controlling access to shared memory in concurrent computing. A transaction in the context of transactional memory is a piece of code that “atomically” executes a series of reads and writes to shared memory. In the traditional model a set of concurrent transactions can commit in any order, but the effects of this executions are as if the transactions executed serially in this order
One possible use of transactional memory is to attempt to speed up sequential programs by automatically (or semi-automatically) introducing speculative parallelism. Thus, several sequentially ordered statements can be executed speculatively, in parallel. This parallel execution may or may not be semantically equivalent to the original sequential execution—if the parallel invocations have data dependencies, where one reads from a location that the other wrote, then they may differ, while invocations without data dependencies may safely execute in parallel. Transactional memory mechanisms can be used to detect such data dependencies; each invocation executes as a transaction, and a data dependency that would require the transactions to serialize in an order other than the sequential order of the invocations causes the violating transaction to be aborted and re-executed.
One problem with taking several sequentially ordered statements and speculatively executing them in parallel is that any exceptions thrown out of speculatively executed statements that are being executed in parallel may not occur in the order that they would have in the original sequential execution. This can lead to incorrect behavior or results.